// const BASE_URL = 'https://temp.china1.fun'
const BASE_URL = 'http://localhost:8088'
export const myRequest = (options) => {
	return new Promise((resolve, reject) => {

		var headers = {
			// 'content-type': 'application/x-www-form-urlencoded',
			'Content-Type': 'application/json;charset=UTF-8',
			'Connection': 'close',
			'Content-Length' : '70',
		};

		let userToken = uni.getStorageSync('token')
		let user = uni.getStorageSync('user')
		let settings = uni.getStorageSync('settings')

		if (!userToken || !user || !settings) {
			uni.reLaunch({
				url: '/pages/login/login'
			})
		}

		uni.request({
			url: BASE_URL + options.url,
			method: options.method || 'GET',
			data: options.data || {},
			header: {
				token: userToken,
			},
			success: (res) => {
				if (res.data === '') {
					uni.removeStorageSync("token")
					uni.removeStorageSync("user")
					uni.removeStorageSync("settings")
					uni.reLaunch({
						url: '/pages/login/login'
					})
					return uni.showToast({
						title: "token过期，从新登陆",
						icon: "none"
					})

				}
				resolve(res)
			},
			fail: (err) => {
				uni.showToast({
					title: '请求接口失败'
				})
				reject(err)
			}
		})
	})
}
